<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改大屏相关配置参数')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-parameter-edit" th:object="${tbLargScreenParamet}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">参数名称：</label>
                <div class="col-sm-8">
                    <select name="name" class="form-control m-b" th:with="type=${@dict.getType('tb_screen_paramet_name')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{name}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">开始日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="parameter1" th:value="${#dates.format(tbLargScreenParamet.parameter1, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">结束日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="parameter2" th:value="${#dates.format(tbLargScreenParamet.parameter2, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">时间间隔(毫秒)：</label>
                <div class="col-sm-8">
                    <input name="parameter3" th:field="*{parameter3}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否有效：</label>
                <div class="col-sm-8">
                    <select name="ifEffect" class="form-control m-b" th:with="type=${@dict.getType('sys_yes_no')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{ifEffect}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/parameter";

        function submitHandler() {
            var name = document.getElementsByName("name")[0].value;
            console.info("name=="+name);
            var icon = "<i class='fa fa-times-circle'></i> ";
            if(name == 'P20220119'){
                $("#form-parameter-edit").validate({
                    rules: {
                        name:"required",
                        parameter1: "required",
                        parameter2: "required"
                    },
                    messages: {
                        name: icon + "请选择参数名称",
                        parameter1: icon + "请选择开始日期",
                        parameter2: icon + "请选择结束日期"

                    }
                });
                $("#p_name").attr("disabled","disabled").css("background-color","#EEEEEE");
            }else if(name == 'P20190814' || name == 'P20201229'){
                $("#form-parameter-edit").validate({
                    rules: {
                        parameter3: {
                            required: true,
                            digits:true
                        }
                    },
                    messages: {
                        required: icon + "请输入时间间隔(单位:毫秒)",
                        digits: icon + "只能输入整数"
                    }
                });
                $("#p_name").attr("disabled","disabled").css("background-color","#EEEEEE");
            }

            if ($.validate.form()) {
                console.info("报错数据》》"+$('#form-parameter-edit').serialize());
                $.operate.save(prefix + "/edit", $('#form-parameter-edit').serialize());
            }
        }

        $("input[name='parameter1']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='parameter2']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>